package com.scu.controller;

import com.scu.pojo.Moderator;
import com.scu.service.ModeratorService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

@Controller
public class ModeratorController {
    @Autowired
    private ModeratorService moderatorService;

    //获取版主列表
    @RequestMapping("getModeratorList")
    @ResponseBody
    public Map getModeratorList(Moderator moderator){
        HashMap<String,Object> map = new HashMap<>();

        //要进行异常捕捉,判断数字 是否为
        List<Moderator>moderatorList =  moderatorService.getModeratorList(moderator);
        map.put("code",0);
        map.put("msg","");
        map.put("data",moderatorList);

        return map;
    }

    //添加版主
    @RequestMapping("addModerator")
    @ResponseBody
    public Map addModerator(Moderator moderator){
        HashMap<String,Object> map = new HashMap<>();

        moderatorService.addModerator(moderator);
        map.put("code",200);
        map.put("msg","");

        return map;
    }



    //删除版主
    @RequestMapping("removeModerator")
    @ResponseBody
    public Map removeModerator(Moderator moderator){
        HashMap<String,Object> map = new HashMap<>();

        moderatorService.removeModerator(moderator);
        map.put("code",200);
        map.put("msg","");
        return map;
    }

    //返回版主总数
    @RequestMapping("getModeratorNum")
    @ResponseBody
    public Map getModeratorNum(){
        HashMap<String,Object> map = new HashMap<>();

        int count = moderatorService.getModeratorNum();
        map.put("code", 200);
        map.put("msg", "");
        map.put("count", count);
        return map;
    }
}

